package com.musichord.reader;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;

public class MidiSequence {
	private Sequence sequence;

	public MidiSequence(String midiFilePath) {
		try {
			this.sequence = MidiSystem.getSequence(new FileInputStream(
					midiFilePath));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidMidiDataException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void getTracks(int trackNo) {
		int size = sequence.getTracks()[trackNo].size();
		System.out.println("sequence.getTracks()[" + trackNo + "].size()="
				+ size);
		for (int i = 0; i < size; i++) {
			MidiMessage me = sequence.getTracks()[trackNo].get(i).getMessage();
			System.out.println(MidiMessageParser.display(me));
		}
		System.out.println();
	}
}
